#!/bin/bash

# Health Check 卸载脚本

set -e

SERVICE_NAME="health-check"
INSTALL_DIR="/opt/health-check"

# 检查是否为 root 用户
if [ "$EUID" -ne 0 ]; then
    echo "请使用 root 用户运行此脚本"
    exit 1
fi

echo "开始卸载 Health Check..."

# 停止并禁用服务
echo "停止服务..."
systemctl stop "$SERVICE_NAME" 2>/dev/null || true
systemctl disable "$SERVICE_NAME" 2>/dev/null || true

# 删除 systemd 服务文件
echo "删除服务文件..."
rm -f "/etc/systemd/system/$SERVICE_NAME.service"
systemctl daemon-reload

# 删除安装目录
echo "删除安装目录..."
rm -rf "$INSTALL_DIR"

# 删除日志文件
echo "删除日志文件..."
rm -f "/var/log/health-check-daemon.log"
rm -f "/var/run/health-check.pid"

echo "卸载完成！"
